package com.example.demo.controller.experycontroller;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.demo.common.ErrorCode;
import com.example.demo.common.Result;
import com.example.demo.entity.Consultation;
import com.example.demo.service.ConsultationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 咨询表(Consultation)表控制层
 *
 * @author makejava
 * @since 2025-01-28 12:36:46
 */
@RestController
@RequestMapping("expert/consultation")
public class ExperyConsultationController {
    /**
     * 服务对象 consultation/list
     */
    @Resource
    private ConsultationService consultationService;
    @GetMapping("list")
    public Result<List<Consultation>> list() {
        return Result.success(consultationService.listAll());
    }
    /**
     * 回复咨询
     * @param id 咨询ID
     * @param reply 回复内容
     * @return 操作结果
     */
    @PostMapping("/reply")
    public Result<Void> reply(@RequestParam("id") Long id, @RequestParam("reply") String reply) {
        if (id == null || StringUtils.isBlank(reply)) {
            return Result.error(ErrorCode.PARAMS_ERROR);
        }
        
        Consultation consultation = new Consultation();
        consultation.setId(id);
        consultation.setDoctorReply(reply);
        consultation.setReplyTime(new Date());
        consultation.setStatus(1);
        
        consultationService.updateById(consultation);
        return Result.success();
    }
    

}

